package nina.yiyou.performance.s20confirm.start

import nina.yiyou.performance.s20confirm.compute.S2ComputeMapMaker
import nina.yiyou.performance.s20confirm.input.BasicExcelReaderV2
import nina.yiyou.performance.s20confirm.input.PerformanceExcelReader
import nina.yiyou.performance.s20confirm.output.PerformConfirmGenerator
import nina.yiyou.salary.input.InfoExcelCollector
import nina.yiyou.salary.input.config.ConfigExcelReader
import nina.yiyou.salary.input.util.InputPathResolver
import nina.yiyou.salary.output.ResultMapMaker

import java.nio.file.Path
import java.nio.file.Paths

class PerformS2Runner {

  PerformS2Runner(Path workshopPath) {
    _workshopPath = workshopPath
  }

  void run() {
    Map<String, String> globalMap = ConfigExcelReader.create(_workshopPath).read().global()

    def (basicMap, performMap) = new InfoExcelCollector([
        ['in.花名册', { String p -> new BasicExcelReaderV2(p).read() }],
        ['in.绩效汇总', { String p -> new PerformanceExcelReader(p).read() }],
    ], globalMap, _workshopPath).collect()

    Path outDir = InputPathResolver.create(_workshopPath, globalMap, 'out.绩效确认').resolve()
    Path tmpDir = Paths.get(outDir.toString() + '_tmp')
    Map computeMap = new S2ComputeMapMaker(basicMap, performMap, outDir, tmpDir).make()

    List<Map> employeeResult = new ResultMapMaker([
        ['基本', basicMap],
        ['绩效', performMap],
        ['计算', computeMap],
    ]).make().values().asList()

    new PerformConfirmGenerator(internal('perform_s20confirm.xlsx'), employeeResult, outDir, tmpDir).generate()
  }

  private Path internal(String name) {
    return _workshopPath.parent.resolve('internal').resolve(name)
  }

  private final Path _workshopPath
}
